package com.ruoyi.system.controller;

import java.util.Date;
import java.util.List;

import cn.hutool.core.date.DateUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysProjectOverview;
import com.ruoyi.system.service.ISysProjectOverviewService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目概况Controller
 *
 * @author ruoyi
 * @date 2022-01-14
 */
@Controller
@RequestMapping("/system/overview")
public class SysProjectOverviewController extends BaseController
{
    private String prefix = "system/overview";

    @Autowired
    private ISysProjectOverviewService sysProjectOverviewService;

    @RequiresPermissions("system:overview:view")
    @GetMapping()
    public String overview()
    {
        return prefix + "/overview";
    }

    /**
     * 查询项目概况列表
     */
    @RequiresPermissions("system:overview:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysProjectOverview sysProjectOverview)
    {
        startPage();
        List<SysProjectOverview> list = sysProjectOverviewService.selectSysProjectOverviewList(sysProjectOverview);
        Date now = new Date();
        for (SysProjectOverview projectOverview : list) {
            projectOverview.setNow(DateUtil.formatDate(now));
        }
        return getDataTable(list);
    }

    /**
     * 导出项目概况列表
     */
    @RequiresPermissions("system:overview:export")
    @Log(title = "项目概况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysProjectOverview sysProjectOverview)
    {
        List<SysProjectOverview> list = sysProjectOverviewService.selectSysProjectOverviewList(sysProjectOverview);
        ExcelUtil<SysProjectOverview> util = new ExcelUtil<SysProjectOverview>(SysProjectOverview.class);
        return util.exportExcel(list, "项目概况数据");
    }

    /**
     * 新增项目概况
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存项目概况
     */
    @RequiresPermissions("system:overview:add")
    @Log(title = "项目概况", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysProjectOverview sysProjectOverview)
    {
        return toAjax(sysProjectOverviewService.insertSysProjectOverview(sysProjectOverview));
    }

    /**
     * 修改项目概况
     */
    @RequiresPermissions("system:overview:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        SysProjectOverview sysProjectOverview = sysProjectOverviewService.selectSysProjectOverviewById(id);
        mmap.put("sysProjectOverview", sysProjectOverview);
        return prefix + "/edit";
    }

    /**
     * 修改保存项目概况
     */
    @RequiresPermissions("system:overview:edit")
    @Log(title = "项目概况", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysProjectOverview sysProjectOverview)
    {
        return toAjax(sysProjectOverviewService.updateSysProjectOverview(sysProjectOverview));
    }

    /**
     * 删除项目概况
     */
    @RequiresPermissions("system:overview:remove")
    @Log(title = "项目概况", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysProjectOverviewService.deleteSysProjectOverviewByIds(ids));
    }
}
